//
//  AlertTableViewCell.m
//  Leo01
//
//  Created by 张旭 on 15/9/22.
//  Copyright (c) 2015年 张旭. All rights reserved.
//

#import "AlertTableViewCell.h"

@implementation AlertTableViewCell
@synthesize navController;
@synthesize timeLabel;
@synthesize detailsLabel;
@synthesize alertOnOff;
-(AlertTableViewCell *)getandSetData:(NSDictionary *)subdic{
    timeLabel.text = [subdic objectForKey:@"time"];
    NSString *newCycle=[self changeSilentCycle:[subdic objectForKey:@"rate"]];
    if ([[subdic objectForKey:@"details"] isEqualToString:@""])
    {
        detailsLabel.text = [NSString stringWithFormat:@"%@%@",[subdic objectForKey:@"details"],newCycle];
    }
    else
    {
    detailsLabel.text = [NSString stringWithFormat:@"%@,%@",[subdic objectForKey:@"details"],newCycle];
    }
    [alertOnOff setOn:[[subdic objectForKey:@"status"]isEqualToString:@"0"]?NO:YES];
    
    
    if (detailsLabel.text.length>20){
        [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 100)];
    }else{
        [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 80)];
    }

    
    return self;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(NSString *)changeSilentCycle:(NSString *)cycle
{
    NSString *newCycle=@"";
    
    if ([cycle isEqualToString:@"1,2,3,4,5,6,7"]){return @"每天";}
    
    for (int i=0;i<cycle.length;i++)
    {
        if (i%2==0)
        {
            NSRange range = NSMakeRange(i, 1);
            NSString *subString = [cycle substringWithRange:range];
            if ([subString isEqual:@"1"]){newCycle=[newCycle stringByAppendingString:@"周一,"];}
            if ([subString isEqual:@"2"]){newCycle=[newCycle stringByAppendingString:@"周二,"];}
            if ([subString isEqual:@"3"]){newCycle=[newCycle stringByAppendingString:@"周三,"];}
            if ([subString isEqual:@"4"]){newCycle=[newCycle stringByAppendingString:@"周四,"];}
            if ([subString isEqual:@"5"]){newCycle=[newCycle stringByAppendingString:@"周五,"];}
            if ([subString isEqual:@"6"]){newCycle=[newCycle stringByAppendingString:@"周六,"];}
            if ([subString isEqual:@"7"]){newCycle=[newCycle stringByAppendingString:@"周日,"];}
        }
        
    }
    if ([newCycle isEqualToString:@""])
    {
        return newCycle;
    }
    else
    {
        NSRange range = NSMakeRange(0, newCycle.length-1);
        newCycle = [newCycle substringWithRange:range];
        return newCycle;
    }
}


@end
